using System.Collections.Generic;
using UnityEngine;

public class KeyboardHandler : MonoBehaviour
{
	private Dictionary<string, KeyCode> keyBindings = new Dictionary<string, KeyCode>
	{
		{
			"Menu",
			KeyCode.Escape
		},
		{
			"Kick",
			KeyCode.Space
		},
		{
			"Kick2",
			KeyCode.LeftControl
		},
		{
			"Reload",
			KeyCode.R
		},
		{
			"SwitchWeapon",
			KeyCode.Q
		},
		{
			"SwitchMeleWeapon",
			KeyCode.E
		},
		{
			"WaveStart",
			KeyCode.Tab
		},
		{
			"Intro",
			KeyCode.F1
		},
		{
			"Item1",
			KeyCode.Alpha1
		},
		{
			"Item2",
			KeyCode.Alpha2
		},
		{
			"Item3",
			KeyCode.Alpha3
		},
		{
			"Item4",
			KeyCode.Alpha4
		},
		{
			"Item5",
			KeyCode.Alpha5
		},
		{
			"Item6",
			KeyCode.Alpha6
		},
		{
			"Item7",
			KeyCode.Alpha7
		},
		{
			"Item8",
			KeyCode.Alpha8
		},
		{
			"Item9",
			KeyCode.Alpha9
		}
	};

	private void Update()
	{
		ListenKey();
	}

	public void ListenKey()
	{
		if (!CampaignGame.Instance || !Input.anyKeyDown)
		{
			return;
		}
		if (Input.GetKeyDown(keyBindings["Menu"]))
		{
			if (CampaignGame.Instance.isPlayground)
			{
				PlaygroundSetting.Instance.Open();
			}
			else
			{
				CampaignGame.Instance.Pause();
			}
		}
		if (Input.GetKeyDown(keyBindings["Kick"]))
		{
			CampaignGame.Instance.player.Kick();
		}
		if (Input.GetKeyDown(keyBindings["Kick2"]))
		{
			CampaignGame.Instance.player.Kick();
		}
		if (Input.GetKeyDown(keyBindings["SwitchWeapon"]))
		{
			CampaignGame.Instance.player.SwapWeapon();
		}
		if (Input.GetKeyDown(keyBindings["SwitchMeleWeapon"]))
		{
			CampaignGame.Instance.player.SwapMeleeWeapon();
		}
		if (Input.GetKeyDown(keyBindings["Reload"]) && (bool)CampaignGame.Instance.player.weapon)
		{
			CampaignGame.Instance.player.weapon.Reload();
		}
		if (Input.GetKeyDown(keyBindings["WaveStart"]))
		{
			CampaignGame.Instance.NextWave();
		}
		if (Input.GetKeyDown(keyBindings["Intro"]))
		{
			CampaignGame.Instance.ShowIntro();
		}
		for (int i = 1; i <= 9; i++)
		{
			if (Input.GetKeyDown(keyBindings["Item" + i]))
			{
				CampaignGame.Instance.player.ThrownItem(i - 1);
			}
		}
	}
}
